package android.project;


  //import android.R;
  import android.app.Activity;
import android.content.ActivityNotFoundException;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
import android.provider.Browser;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuItem;
  import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
  import android.webkit.WebView;
import android.webkit.WebView.HitTestResult;
  import android.webkit.WebViewClient;
  import android.widget.Button;
import android.widget.Toast;

  public class MediaEx extends Activity implements DownloadListener {
  	
	WebView wv;

      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.mediaex);
          
          wv = (WebView) findViewById(R.id.webView1);
          //((Button)findViewById(R.id.b1)).setOnClickListener(listener);
          //((Button)findViewById(R.id.b2)).setOnClickListener(listener);
          //((Button)findViewById(R.id.b3)).setOnClickListener(listener);
          
          //((Button)findViewById(R.id.backward)).setOnClickListener(listener);
          //((Button)findViewById(R.id.forward)).setOnClickListener(listener);
     
          wv.getSettings().setJavaScriptEnabled(true);//javaSCript
			wv.getSettings().setPluginsEnabled(true);//youtube 
			wv.getSettings().setBuiltInZoomControls(true);//zoom
			wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
			wv.getSettings().setLightTouchEnabled(true);
			wv.getSettings().setSavePassword(true);
			wv.getSettings().setSaveFormData(true);
			
			wv.getSettings().setSupportMultipleWindows(true);
	          wv.getSettings().setSupportZoom(true);
	          wv.getSettings().setBuiltInZoomControls(true);
	          wv.getSettings().setBlockNetworkImage(true);
	          wv.getSettings().setLoadsImagesAutomatically(false);
	          wv.getSettings().setUseWideViewPort(true);
	          wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
			
			
			wv.setWebChromeClient(new WebChromeClient(){
				public boolean onJsAlert(WebView view, String url, String message, JsResult result){
		    		  Toast.makeText(MediaEx.this, message, Toast.LENGTH_SHORT).show();
		    		  result.confirm();
		    		  
		    		  return true;
		    	  }
		      });
			
			//wv.loadUrl("http://www.google.co.kr/url?sa=t&rct=j&q=resume&source=web&cd=1&sqi=2&ved=0CEgQFjAA&url=http%3A%2F%2Finternplan.com%2F1%2Fimg%2Fsample_resume.doc&ei=j-rRTtjCBpDSmAXjh8DBDQ&usg=AFQjCNH31dhYj7wqkYlTaqkj0BZHlJ9CcQ&sig2=E4b-IFqcVB-n9xxIyUwgTw&cad=rjt");
			//wv.loadUrl("file:///android_assert/jsalert.html");
			wv.loadUrl("http://www.daum.net");
			//wv.setWebViewClient(new WebView1Client());
			
      }
      /*
      Button.OnClickListener listener = new View.OnClickListener(){
      	public void onClick(View view){
      		switch(view.getId()){
      		case R.id.b1:
      			
      			break;  
      			/*
      		case R.id.b2:
      			wv.loadUrl("file:///android_asset/file1.html");
      			break;
      		case R.id.b3:
      			final String mimeType = "text/html";
      			final String encoding = "UTF-8";
      			String html = "<H1>ahh~ <H1><body>"+"<p>okokok<br>ㅋㅋㅋ</p>";
      			wv.loadDataWithBaseURL("",html,mimeType, encoding, "");
      			break; 
      			 
      
      		case R.id.backward:
      			if(wv.canGoBack())
      				wv.goBack();
      			break;
      		case R.id.forward:
      			if(wv.canGoForward())
      				wv.goForward();
      			break;
      		default:
      			Toast.makeText(getBaseContext(), "Error!", Toast.LENGTH_LONG).show();    			
      		}
      	}
      };
      */
      
      
      
      private class WebView1Client extends WebViewClient {
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
              if (url.endsWith(".3gp")) {
            	  boolean flag=false;
                  Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
                  view.getContext().startActivity(intent);    
                 return true;
              }else {
            	  
                  return super.shouldOverrideUrlLoading(view, url);
              }
          }
      }




	public void onDownloadStart(String url, String userAgent,
			String contentDisposition, String mimetype, long contentLength) {
		// TODO Auto-generated method stub
		//Log.i(TAG, "Download: " + url);
        //Log.i(TAG, "Length: " + contentLength);
	}
      
  }

